assignmentstatement
Assignment statements are used to (re)bind names to values and to
modify attributes or items of mutable objects:
bindingname
rebindingname
mutable
attributeassignment
assignment_stmt: (target_list "=")+ expression_list
target_list: target ("," target)* [","]
target: identifier | "(" target_list ")" | "[" target_list "]"
| attributeref | subscription | slicing
(See section
for the syntax definitions for the last
three symbols.)
An assignment statement evaluates the expression list (remember that
this can be a single expression or a comma-separated list, the latter
yielding a tuple) and assigns the single resulting object to each of
the target lists, from left to right.
expressionlist
Assignment is defined recursively depending on the form of the target
(list). When a target is part of a mutable object (an attribute
reference, subscription or slicing), the mutable object must
ultimately perform the assignment and decide about its validity, and
may raise an exception if the assignment is unacceptable. The rules
observed by various types and the exceptions raised are given with the
definition of the object types (see section
).
targetlist
Assignment of an object to a target list is recursively defined as
follows.
targetlistassignment
- If the target list is a single target: the object is assigned to that
target.
- If the target list is a comma-separated list of targets: the object
must be a tuple with the same number of items as the list contains
targets, and the items are assigned, from left to right, to the
corresponding targets.
Assignment of an object to a single target is recursively defined as
follows.